<template>
  <div>
    <ul>
      <li>
        <a href="JavaScript:;" @click="$router.push('/contacts/allcontacts')"
          >All contacts</a
        >
      </li>
      <li>
        <a href="JavaScript:;" @click="$router.push('/contacts/alice')"
          >Alice</a
        >
      </li>
      <li>
        <a href="JavaScript:;" @click="$router.push('/contacts/bob')">Bob</a>
      </li>
    </ul>
    <button @click="goView">随机显示</button>
    <div class="box">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        // ；将二级路由存放在一个数组
        childernViews: ['allcontacts', 'alice', 'bob'],
      }
    },
    methods: {
      goView() {
        // 随机数
        const num = Math.floor(Math.random() * this.childernViews.length)
        // console.log(num)
        this.$router.push(`/contacts/${this.childernViews[num]}`)
      },
    },
  }
</script>

<style>
</style>